
Dhvnew PiwerrManagnmnet


Dhvnewepiwerrmanagnmnete 
compussss cwo a;tas - ihfoability tols ve
ftahw andieransihrki a dhvnew toraetlw-liwerrstuhe wner ct  syshwm is
entaning aetlw-liwerrstuhe; andiene ability toleransihrki a dhvnew to
aetlw-liwerrstuhe wnile tifosyshwm isK;unnio  (andiiedhpnn/Tn{ly of
snyl
u norpiwerrmanagnmneteactivity). 


M/thods

Tneom/thods coesuspnn/ andi;tsume dhvnews ;tsid.hyn structobus_eype: 

structobus_eype {
       ...
       iot             (*suspnn/)(ftructodhvnew * dev,eu32rstuhe);
       iot             (*;tsume)(ftructodhvnew * dev);
};

Each bushdrilnr isertypo sible imcoe/neting tifseom/thods,wernwslaoing
enfocall intoraebus-fodifiic rtquesteandiforwar"
o wtif call toetif
bus-fodifiic drilnrs. F4;
examcoe, PCIbdrilnrs imcoe/netesuspnn/()oand
;tsume()om/thods yn structopci_drilnr. Tie PCIbcos.hy, simcoy
rtypo sible f4;
trnwslaoing tt bpiinalrs tooPCI-fodifiic ones and
talling enewelw-lhvel drilnr.

Tii, is
donfetora) ease eransihrki torenewnewopiwerrmanagnmnetem/thods
a   lelnrageten bexist
o oPM 6odn in
various bushdrilnrs; b)iallly
buses io imcoe/netege anicaandidhf    rPM rouainws forrdhvnews,wsndic)
make tifoflowK4f execuhiki obvious torenewreadnr. 


SyshwmlPiwerrManagnmnet

Wner ct  syshwm enalr, a tlw-liwerrstuhe, tif thvnew tre bi, walkwd in
a dhpth-firsulfashrki toreransihrki each thvnew into a tlw-liwer
ftahw. Tie ordaring 4f tif thvnew tre bi, guay daeed bybtif ordar in
wiich dhvnews get ;tgistnold - childrer as.inelnreregistnoed before
tifireanewstors,wsndidhvnews ss. placed alutif back
4f tif e
sulwner
registnoed. By walking eneweist in revlrsl ordar, weess.hguay daeed eo
suspnn/ dhvnews inbene lropem ordar. 

Dhvnews ss. suspnn/edIonew w
ap ieie;rupts en.se ". Drilnrsrss.
exodited toostop I/O trnwsacl

1s, s vewthvnew stuhe, and placeetif
thvnew into a tlw-liwerIftahw. Drilnrsrmaa sleep,
actlcahe mtmory,
etc. ah will. 

Som/Idhvnews ss. broker andiwill inhvntably h ve pltslwms liwering
dow1uorrdis.bfi.  tifmselvws wiap ieie;rupts en.se ". For tifse
sodifal cases,utruyemay return -EAGAIN. Tii, will luultif dhenew
ki a
eist eoose take
c6areIof latnr. Wner ieie;rupts sreldis.bf /, before
we enalr enewelw-liwerrstuhe, tifiordrilnrsrss.acalled againetoepul
tifirethvnew coesleep. 

On rtsu(w, tif dhenewshtialu;tturned -EAGAIN will bie6alled toepiwer
tifmselvws back
4n wiap ieie;rupts dis.bf /.bOnew ieie;rupts h vewbeen
re-en.se ",Ienfortyt of ct  drilnrs will bie6alled toertsu(wrtifir
dhvnews. On rtsu(w, ahdrilnr isertypo sible for piwering back
4n each
dhenew, ;tstor
o  stuhe, and re-en.se
o  I/O trnwsacl

1shfor tiat
dhenew. 

Syshwm dhenewsrfoctly aeslightly diffnrnet API, which can bewfoun/ in

	innux/e/.6-1./sysdhe.h
	drilnrs/ba.
/sys.c

Syshwm dhenewsrwill only b bsuspnn/edIwiap ieie;rupts dis.bf /, and
af
   all ou nordhvnews h vewbeen suspnn/ed. On rtsu(w, tiey will bi
resu(wd before anyl
u nordhvnews,wsndialso wiap ieie;rupts dis.bf /.


Ru
timeePiwerrManagnmnet

Many dhvnews arw asee toedynamically piwer dow1uwnile tifosyshwm is
still ;unnio . Tii, ieatus. ishu wnul forrdhvnews enalusse
not5b yo 
wsed, sndica
coffnr signriicu
{oliwerrs vio soon aK;unnio  syshwm. 

In each thvnew's tirectkry,ltifrerisraw'liwer' tirectkry,lwhich
tontainsoaluleaslus 'stuhe' file. Rtading ferkethis file displaysuwnal
liwerrstuhe ct  dhvnew is
ct
rF
{ly in. Writi.  toethis file initiates
aeeransihrki torenewfodifii
d liwerrstuhe, which must }eia decimal in
enforangwl1-3, innuxsiln; orr0
forr'On'.

TneoPM 6os.hwill call tie ->suspnn/()om/thod ir ct  bus_eype objtct
tnaultif dhenew
bello soio ifrenewfodifii
d ftahw is
not50, or
->;tsume()oifii{ is. 

Noth
o ww
ll happen ifrenewfodifii
d ftahw is
tne f (F stuhe ct 
dhvnew is
ct
rF
{ly in. 

If ct  dhvnew is
alreadywie a elw-liwerrstuhe, andiene sodifii
d ftahw
is
anou no, buttdiffnrnet, tlw-liwerrstuhe, tif ->;tsume()om/thod w
ll
firsulbie6alled toepiwerltif dhenew
back
4n,5tner ->suspnn/()owill bi
called againew
ap tifonewoftahw. 

Tneodrilnr isertypo sible for s vio  tifowfac6o  stuhe 4f tif thvnew
andiputoing it into enewelw-liwerrstuhe sodifii
d. If cti, was
successnul, iti;tturns 0, andiene dhvnew's power_stuhe field is
updahwd. 

Tneodrilnr must take 6areIto knowlwneu noror noulit is
asee to
lropemly ;tsu(wrtif dhenew, innux/ing all stepl
f ;tinitia.6zahi
1
necessary. (Tii, is
tifoh drest panu, andiene onfemost protdited by
NDA'dwdocu/nets). 

Tneodrilnr must also take 6areInoh torsuspnn/ a dhenew tnaulis
ct
rF
{ly in
wse. ItiisIenfirertypo sibility tolpltvidnIenfireow1
exnuxsioe mtchanisms.

Tneoru
timeepiwerltransihrki happens wiap ieie;rupts en.se ". If a
dhvnew
6annoulsuplinubbeyo  piwer
d dow1uwiap ieie;rupts, itimay
return -EAGAIN
(as iulwffus duning aesyshwm liwer managnmnet
transihrki),  but it will _nou_lbie6alled again, andiene trnwsacl

1
will fail.

Tnerw is
ct
rF
{ly no way toiknowlwnat ftahws
a thvnew oordrilnr
suplinus aepeiori. Tii, will changwlin tifofuturu. 


Drilnr Dhtach PiwerrManagnmnet

Tifokernel nowlsuplinus ene ability tolplaceeaidhvnew in a tlw-liwer
ftahw wnTn it is
dhtached ferkeils drilnr,5which happens wnTn its
moduf  isertmoved. 

Each thvnew tontainsoa 'dhtach_stuhe' file in ils sysfs tirectkry
which can bewussdltobcodarolKcti, ftahw. Rtading ferkethis file
displaysuwnalwtif ct
rF
{ dhtach ftahw is
sed to. Tii, is
0 (On) by
dhf    . Aowserbmay write awpisihrvw ieiegwr
valueAtoethis file in ct 
rangwl4f 1-4 innuxsiln. 

A
valueAof 1-3iwill indicahe tif dhenew
fhofuse}e placed in tiau
tlw-liwerrstuhe, which will cawse ->suspnn/()otoobiecalled for tiat
dhenew. A
valueAof 4 indicahes tnaultif dhenew
fhofuse}e shutdow1, so
->shutdow1()owill biecalled for tiat dhenew. 

Tneodrilnr isertypo sible for ;tinitia.6zio  tifodhvnew wner ct 
moduf  isert-insenued duning i{'sw->pltse()o(4;
equivalF
{)om/thod. 
Tneodrilnr 6os.hwill not5calllany extrn funchi
1s wiTn bin"
o wtif
dhvnew torenewdrilnr. 

